package cn.mw.cmdb.controller;

import cn.mw.cmdb.entity.modelRelation.AddAndUpdateModelRelationParam;
import cn.mw.cmdb.entity.modelRelation.RelationGroupDTO;
import cn.mw.cmdb.service.ModelRelationService;
import cn.mw.microMonitorCommon.api.common.BaseApiService;
import cn.mw.microMonitorCommon.api.common.ResponseBase;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/modelRelation")
@Controller
@Tag(name = "模型关系")
@Slf4j
public class ModelRelationController extends BaseApiService {

    @Autowired
    private ModelRelationService modelRelationService;

    @GetMapping("/getModelRelation")
    @ResponseBody
    @Operation(summary = "查询模型关系")
    public ResponseBase getModelRelation(String modelId) throws Exception {
        return setResultSuccess(modelRelationService.getModelRelation(modelId));
    }

    @PostMapping("/createModelRelationGroup")
    @ResponseBody
    @ApiOperation(value = "创建模型关系分组")
    public ResponseBase createModelRelationGroup(@RequestBody RelationGroupDTO param) {
        return setResultSuccess(modelRelationService.creatModelRelationsGroup(param));
    }

    @GetMapping("/getRelationGroupInfoById")
    @ResponseBody
    @Operation(summary = "查询模型关系分组详情")
    public ResponseBase getRelationGroupInfoById(String groupId) throws Exception {
        return setResultSuccess(modelRelationService.getRelationGroupInfoById(groupId));
    }

    @GetMapping("/getRelationGroupInfoByModelId")
    @ResponseBody
    @Operation(summary = "查询模型关系分组")
    public ResponseBase getRelationGroupInfoByModelId(String modelId) throws Exception {
        return setResultSuccess(modelRelationService.getRelationGroupInfoByModelId(modelId));
    }

    @GetMapping("/deleteModelRelationsGroup")
    @ResponseBody
    @Operation(summary = "删除模型关系分组")
    public ResponseBase deleteModelRelationsGroup(String groupId) throws Exception {
        return setResultSuccess(modelRelationService.deleteModelRelationsGroup(groupId));
    }

    @PostMapping("/editModelRelationsGroup")
    @ResponseBody
    @ApiOperation(value = "修改模型关系分组")
    public ResponseBase editModelRelationsGroup(@RequestBody RelationGroupDTO param) throws Exception {
        return setResultSuccess(modelRelationService.editModelRelationsGroup(param));
    }

    @PostMapping("/createModelRelation")
    @ResponseBody
    @ApiOperation(value = "创建模型关系")
    public ResponseBase createModelRelation(@RequestBody AddAndUpdateModelRelationParam param) throws Exception {
        return setResultSuccess(modelRelationService.creatModelRelation(param));
    }

    @PostMapping("/deleteModelRelation")
    @ResponseBody
    @ApiOperation(value = "删除模型关系")
    public ResponseBase deleteModelRelation(@RequestBody AddAndUpdateModelRelationParam param) throws Exception {
        return setResultSuccess(modelRelationService.deleteModelRelation(param));
    }

    @PostMapping("/editModelRelation")
    @ResponseBody
    @ApiOperation(value = "修改模型关系")
    public ResponseBase editModelRelation(@RequestBody AddAndUpdateModelRelationParam param) throws Exception {
        return setResultSuccess(modelRelationService.editModelRelation(param));
    }

    @PostMapping("/getModelRelationDetail")
    @ResponseBody
    @ApiOperation(value = "查看模型关系详情")
    public ResponseBase getModelRelationDetail(@RequestBody AddAndUpdateModelRelationParam param) throws Exception {
        return setResultSuccess(modelRelationService.getModelRelationDetail(param));
    }
}
